
import requests
print("=========做get请求===============")
r = requests.get("http://httpbin.org/get")
# text 内容
print(r.text)
#结果
"""
text的内容
{
    "args":{},
    "headers":{
        "Accept":"*/*",
        "Accept-Encoding":"gzip, deflate",
        "Host": "httpbin.org",
        "User-Agent":"python-requests/2.26.0",
        "X-Amzn-Trace-Id":"Root=1-61d2e8e9-17518b2601f0c2977b4f05b7"
    }
    "origin":"182.105.80.242",
    "url": "http://httpbin.org/get"
}
"""
print("================================")



# 请求参数写法
# 写法一
print("=========请求参数写法一============")
r1 = requests.get('http://httpbin.org/get?name=germey&age=20')
print(r1.text)
#结果
"""
{
  "args": {
    "age": "20", 
    "name": "germey"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.32.3", 
    "X-Amzn-Trace-Id": "Root=1-677de873-11e10ae44f2e5f2b36042096"
  }, 
  "origin": "60.247.6.130", 
  "url": "http://httpbin.org/get?name=germey&age=20"
}
"""
print("================================")
# 写法二
print("=========请求参数写法二============")
data={
    'name': 'germey',
    'age': 20
}
r2 = requests.get('http://httpbin.org/get',params=data)
print(r2.text)
# 结果
"""
{
  "args": {
    "age": "20", 
    "name": "germey"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.32.3", 
    "X-Amzn-Trace-Id": "Root=1-677de874-580aec981728e8064fca08f4"
  }, 
  "origin": "60.247.6.130", 
  "url": "http://httpbin.org/get?name=germey&age=20"
}
"""
print("================================")

#返回内容、返回内容的类型
print(type(r.text)) # str类型
print(r.json()) #返回响应内容的字典形式
print(type(r.json())) #dict类型
